home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / Src / Ch1 / Auto.frm (.txt) next >
Visual Basic Form  |  1999-03-18  |  3KB  |  92 lines

  1. VERSION 5.00
  2. Begin VB.Form frmAuto 
  3.    Caption         =   "Auto"
  4.    ClientHeight    =   4365
  5.    ClientLeft      =   1140
  6.    ClientTop       =   1515
  7.    ClientWidth     =   7095
  8.    LinkTopic       =   "Form1"
  9.    PaletteMode     =   1  'UseZOrder
  10.    ScaleHeight     =   4365
  11.    ScaleWidth      =   7095
  12.    Begin VB.PictureBox PaintPict 
  13.       Height          =   4095
  14.       Left            =   3600
  15.       ScaleHeight     =   269
  16.       ScaleMode       =   3  'Pixel
  17.       ScaleWidth      =   229
  18.       TabIndex        =   1
  19.       Top             =   240
  20.       Width           =   3495
  21.    End
  22.    Begin VB.PictureBox AutoPict 
  23.       AutoRedraw      =   -1  'True
  24.       Height          =   4095
  25.       Left            =   0
  26.       ScaleHeight     =   269
  27.       ScaleMode       =   3  'Pixel
  28.       ScaleWidth      =   229
  29.       TabIndex        =   0
  30.       Top             =   240
  31.       Width           =   3495
  32.    End
  33.    Begin VB.Label Label1 
  34.       Alignment       =   2  'Center
  35.       Caption         =   "Paint Events"
  36.       Height          =   255
  37.       Index           =   1
  38.       Left            =   3600
  39.       TabIndex        =   3
  40.       Top             =   0
  41.       Width           =   3495
  42.    End
  43.    Begin VB.Label Label1 
  44.       Alignment       =   2  'Center
  45.       Caption         =   "AutoRedraw"
  46.       Height          =   255
  47.       Index           =   0
  48.       Left            =   0
  49.       TabIndex        =   2
  50.       Top             =   0
  51.       Width           =   3495
  52.    End
  53. Attribute VB_Name = "frmAuto"
  54. Attribute VB_GlobalNameSpace = False
  55. Attribute VB_Creatable = False
  56. Attribute VB_PredeclaredId = True
  57. Attribute VB_Exposed = False
  58. Option Explicit
  59. ' Draw squiggly lines.
  60. Private Sub DrawPict(ByVal pic As PictureBox)
  61. Const Amp = 3
  62. Const PI = 3.14159
  63. Const Per = 4 * PI
  64. Dim i As Single
  65. Dim j As Single
  66. Dim hgt As Single
  67. Dim wid As Single
  68.     pic.ScaleMode = vbPixels
  69.     pic.Cls     ' Clear the picture box.
  70.     For i = 0 To pic.ScaleHeight Step 4
  71.         pic.CurrentX = 0
  72.         pic.CurrentY = i
  73.         For j = 0 To pic.ScaleWidth
  74.             pic.Line -(j, i + Amp * Sin(j / Per))
  75.         Next j
  76.     Next i
  77.     For i = 1 To hgt Step 2
  78.         pic.Line (0, i)-(wid, i)
  79.     Next i
  80. End Sub
  81. ' Draw on the PictureBox with AutoRedraw = True.
  82. Private Sub Form_Load()
  83.     DrawPict AutoPict
  84. End Sub
  85. ' Draw on the PictureBox with AutoRedraw = False.
  86. Private Sub PaintPict_Paint()
  87.     ' This makes the other PictureBox refresh
  88.     ' itself before we start hogging the CPU.
  89.     Refresh
  90.     DrawPict PaintPict
  91. End Sub
  92.